﻿using System.Drawing;
using System.Windows.Forms;
using DrawTools.Editor;
using DrawTools.Editor.CanvasFigures;

namespace DrawTools.Tools
{
  public class CropTool : ObjectTool
  {
    public CropTool()
    {
      Cursor = Cursors.Cross;
    }

    public override void OnMouseDown(IDrawingCanvas canvas, MouseEventArgs e)
    {
      canvas.Crop = new CanvasCrop(e.X, e.Y, 1, 1)
      {
        IsSelected = false
      };
    }

    public override void OnMouseMove(IDrawingCanvas canvas, MouseEventArgs e)
    {
      canvas.SetCursor(Cursor);

      if (e.Button == MouseButtons.Left)
      {
        var point = new Point(e.X, e.Y);
        canvas.Crop.MoveHandleTo(point, 5);
        canvas.Refresh();
      }
    }

    public override void OnMouseUp(IDrawingCanvas canvas, MouseEventArgs e)
    {
      canvas.Crop.IsSelected = true;
      canvas.Crop.Normalize();
      canvas.CaptureMouse = false;
      canvas.Refresh();
    }
  }
}